﻿<%@ Page Title="Handling client events" Language="C#" MasterPageFile="~/Demo.master"
    StylesheetTheme="start" Inherits="DemoPage" %>

<%@ Register Src="~/CodeFormatter.ascx" TagName="Code" TagPrefix="demo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="DemoHolder" runat="Server">
    <style type="text/css">
        .draggablePanel { width: 16em; padding: 0 1em; }
        .draggablePanel ul li { margin: 1em 0; padding: 0.5em 0; }
        .draggablePanel ul li span.ui-icon { float: left; }
        .draggablePanel ul li span.count { font-weight: bold; }
    </style>
    <div class="dna-state-help ui-corner-all" style="margin-bottom: 10px;">
        (jQuery ui draggable plugin help:)Layer functionality onto the draggable using the start, drag, and stop events. Start
        is fired at the start of the drag; drag during the drag; and stop when dragging
        stops.
        <p>
          DJ Draggable WebControl Provides <b>OnClientDragStart</b>,<b>OnClientDragStop</b>,<b>OnClientDrag</b> event property to catch 
          the client events.You can write javascript string in these properties directly on server side.
          <br />e.g:<br />
          <code>
              OnClientDrop="alert(ui.position.top);"
          </code> 
        </p>
    </div>
    <asp:Panel ID="Panel1" runat="server" CssClass="draggablePanel ui-widget-content"
        Height="200px" Width="200px">
        <p>
            Drag me to trigger the chain of events.</p>
        <ul class="ui-helper-reset">
            <li class="ui-state-default ui-corner-all" id="event-start"><span class="ui-icon ui-icon-play">
            </span>"start" invoked <span class="count">0</span>x</li>
            <li class="ui-state-default ui-corner-all" id="event-drag"><span class="ui-icon ui-icon-arrow-4">
            </span>"drag" invoked <span class="count">0</span>x</li>
            <li class="ui-state-default ui-corner-all ui-state-hover" id="event-stop"><span class="ui-icon ui-icon-stop">
            </span>"stop" invoked <span class="count">0</span>x</li>
        </ul>
    </asp:Panel>
    <DotNetAge:Draggable ID="Draggable1" runat="server" OnClientDrag="counts[1]++;updateCounterStatus($drag_counter,counts[1]);"
        OnClientDragStart="counts[0]++;updateCounterStatus($start_counter,counts[0]);"
        OnClientDragStop="counts[2]++;updateCounterStatus($stop_counter,counts[2]);">
        <Target TargetID="Panel1" />
    </DotNetAge:Draggable>

    <script type="text/javascript">
        var counts = [0, 0, 0];
        var $start_counter;
        $().ready(function() {
            $start_counter = $('#event-start'), $drag_counter = $('#event-drag'), $stop_counter = $('#event-stop');
            
        });
        function updateCounterStatus($event_counter, new_count) {
            // first update the status visually...
            if (!$event_counter.hasClass('ui-state-hover')) {
                $event_counter.addClass('ui-state-hover').siblings().removeClass('ui-state-hover');
            }
            // ...then update the numbers
            $('span.count', $event_counter).text(new_count); 
        }
    </script>
   <br />
    <demo:Code runat="server" ID="codeView" SourceFile="~/Draggable/Codes/Events.aspx" />
</asp:Content>
